package com.fzdy.dataplatform.service.impl;

import com.fzdy.dataplatform.core.dao.Dao;
import com.fzdy.dataplatform.core.service.impl.BaseServiceImpl;
import com.fzdy.dataplatform.dao.BusinessDao;
import com.fzdy.dataplatform.dao.UserKtvBusinessDao;
import com.fzdy.dataplatform.entity.Business;
import com.fzdy.dataplatform.entity.UserKtvBusiness;
import com.fzdy.dataplatform.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

@Service
@Transactional
public class BusinessServiceImpl extends BaseServiceImpl<Business> implements BusinessService {
    @Autowired
    private BusinessDao businessDao;
    @Autowired
    private UserKtvBusinessDao userKtvBusinessDao;


    @Override
    protected Dao getDao() {
        return businessDao;
    }

    @Override
    public void batchDelete(Serializable[] ids){
        for (Serializable id:ids){
            UserKtvBusiness ktvBusiness=new UserKtvBusiness();
            ktvBusiness.setBusinessid((Integer) id);
            List<UserKtvBusiness> list = userKtvBusinessDao.findByExampleEq(ktvBusiness);
            if (list.size()>0){
                userKtvBusinessDao.deleteT(list.get(0).getId());
            }
            Business business=businessDao.get(id);
            business.setStatus(0);
            business.setKey(null);
            businessDao.update(business);
        }
    }
}
